package weixinkeji.dev.dc.base.refectory.h;

import sys.wx.c.ATR;
import sys.wx.c.components.cv.CV;
import sys.wx.ann.hm.H;
import sys.wx.ann.hm.M;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.base.refectory.bean.Refectory;
import weixinkeji.dev.dc.base.refectory.bean.fl.RefectoryFL;

/**
 *
 * @author IK
 */
@H("weixinkeji/dev/dc/base/refectory/adu")
public class RefectoryADU {

    ATR a;                  //ATR是必须要的。它封装了web请求的相关信息

    public RefectoryADU(ATR obj) {     //这个有参构造函数，也是必须的。它进行附值
        this.a = obj;
    }

    @M("/add")
    public String a1() {
        Refectory obj = CV.getObject_Add(Refectory.class, a.request, new weixinkeji.dev.dc.base.refectory.check.RefectoryCheck().doRefectory(false));
        if (null == obj) {
            a.out_OK_NO(false, "您提交的数据存在格式问题。请注意数据字符的输入");
            return null;
        } else if (Dao.selectCount(Refectory.class, Where.putThenGet(Where.TJ_IGNORE_EMPTY_NULL, null, "", "refectory_code", "=", obj.getRefectory_code())) != 0) {
            a.out_OK_NO(false, "编码重复。请换个编码。");
            return null;
        }

        a.out_OK_NO(Dao.add(obj));
        return null;
    }

    @M("/dell")
    public String d() {
        String id = a.request.getParameter("id");
        if (id.length() < 26) {
            return null;
        }
        a.out_OK_NO(Dao.dell_vast(Refectory.class, id));
        return null;
    }

    @M("/update")
    public String u() {
        return null != a.request.getParameter("id") ? select1(a.request.getParameter("id")) : update();
    }

    private String select1(String x) {
        Refectory cb = Dao.selectOneByID(Refectory.class, x);
        a.request.setAttribute("Refectory", cb);
        a.request.setAttribute("RefectoryFL_P", Dao.selectOneByID(RefectoryFL.class, cb.getFlid()));
        return "/dc_manager/base/refectory/refectory_U.jsp";
    }

    private String update() {
        Refectory obj = CV.getObject(Refectory.class, a.request, new weixinkeji.dev.dc.base.refectory.check.RefectoryCheck().doRefectory(true));
        if (null == obj) {
            a.out_OK_NO(false, "您提交的数据存在格式问题。请注意数据字符的输入");
            return null;
        }
        a.out_OK_NO(Dao.updateReject(obj, "refectory_code"));
        return null;
    }
}
